;(function($,window,documnet){
function registerLongPressEvent(target,cbk,timeInterval) {
var timer;
var evt = document.createEvent('Event');
evt .initEvent('longPress', true, true);
target.addEventListener('mousedown', function() {
timer=setTimeout(function(){
target.dispatchEvent(evt);
},timeInterval);
}, false);
target.addEventListener('mouseup', function() {
clearTimeout(timer);
}, false);
target.addEventListener('longPress',cbk, false);
}
$.fn.addEvent=function(name,cbk){
return this.each(function(){
var $this=$(this);
cbk=cbk||function(){};
switch (name){
case 'longPress':
registerLongPressEvent($this[0],cbk,1000);
break;
default:
break;
}
});
}
$.fn.longPress=function(cbk){
return this.each(function(){
var $this=$(this);
cbk=cbk||function(){};
registerLongPressEvent($this[0],cbk,1000);
});
}
})(jQuery,window,document,undefined);
Jquery 长按事件的实现
原创文章,作者:ikme,如若转载,请注明出处:https://ikme.cn/JavaScript/3.html
打赏 微信扫一扫 支付宝扫一扫
将List数据快速转换为Tree 树结构
上一篇
2024-4-19 10:02
一款功能强悍的手机电脑同屏工具,不仅开源还无需root 14K star
下一篇
2024-4-19 14:28
收藏
扫描二维码,在手机上阅读